Banco de Dados

dados<-read_csv("cases-brazil-cities-time_2022.csv.gz")
dados<-dados%>%
  filter(state=="PA")%>%
  filter(date>"2022-10-31" & date<"2022-12-01")
total_casos<-dados%>%
  group_by(as.character(ibgeID))%>%
  summarise(casos_total=sum(newCases), city=Mode(city))
shape<-st_read("PA_Municipios_2021.shp")
## Reading layer `PA_Municipios_2021' from data source 
##   `C:\Users\hcgea\OneDrive\Documentos\PA_Municipios_2021.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 144 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -58.89833 ymin: -9.841153 xmax: -46.06142 ymax: 2.591027
## CRS:           NA
shape$nome<-paste(shape$NM_MUN, "/", shape$SIGLA, sep="")
shape<-shape[,-(1:4)]
total_casos<-total_casos[-1,]
mapa<-merge(x=shape, y=total_casos, by=intersect('geometry', 'as.character(ibgeID)'))
mapa$local<-as.data.frame(ifelse(mapa$nome!=mapa$city, NA, mapa$city))
mapa<-mapa%>%drop_na()
mapa$texto<-paste(mapa$nome, ":", mapa$casos_total, "casos")
mapa<-mapa[,-(4:5)]

Mapa

grafico<-ggplot(mapa, 
                aes(x = reorder(nome, casos_total), 
                    y = casos_total,
                    tooltip = texto, data_id = nome)) +
  geom_col_interactive(color="gray", fill="purple", size=0.5) + 
  theme_light() +
  theme(axis.text=element_text(size = 1)) +  #<<
  labs(title = "Casos de Covid em Novembro de 2022 no PA",
       subtitle = "Fonte: https://github.com/wcota/covid19br"
  ) + ylab("") + xlab("") + coord_flip()
mapa<-ggplot(data=mapa, aes(fill=total_casos$casos_total), color="white") +
  geom_sf_interactive(size = 0.125, aes(data_id = nome, tooltip = nome)) +
  scale_fill_viridis_c(option="rocket", name="nº de casos", direction=-1) +
  labs(x=NULL, y=NULL, 
       title="Pará") + 
  theme_light()
girafe(ggobj = mapa + grafico, 
       width_svg = 10, height_svg = 5) %>%
  girafe_options(opts_hover(css = "fill:cyan;"))